package com.google.shop.product.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;

/* loaded from: app.jar:BOOT-INF/classes/com/google/shop/product/utils/HttpRequest.class */
public class HttpRequest {
    public static String sendGet(String url, String param) {
        String result = "";
        BufferedReader in = null;
        try {
            try {
                URLConnection connection = new URL(url + "?" + param).openConnection();
                connection.setRequestProperty("accept", "*/*");
                connection.setRequestProperty("connection", "Keep-Alive");
                connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
                connection.connect();
                for (String str : connection.getHeaderFields().keySet()) {
                }
                in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                while (true) {
                    String line = in.readLine();
                    if (line == null) {
                        break;
                    }
                    result = result + line;
                }
                if (in != null) {
                    try {
                        in.close();
                    } catch (Exception e2) {
                        e2.printStackTrace();
                    }
                }
            } catch (Exception e) {
                System.out.println("发送GET请求出现异常！" + e);
                e.printStackTrace();
                if (in != null) {
                    try {
                        in.close();
                    } catch (Exception e22) {
                        e22.printStackTrace();
                    }
                }
            }
            return result;
        } catch (Throwable th) {
            if (in != null) {
                try {
                    in.close();
                } catch (Exception e23) {
                    e23.printStackTrace();
                    throw th;
                }
            }
            throw th;
        }
    }

    public static String sendPost(String url, String param) throws IOException {
        PrintWriter out = null;
        BufferedReader in = null;
        String result = "";
        try {
            try {
                URLConnection conn = new URL(url).openConnection();
                conn.setRequestProperty("accept", "*/*");
                conn.setRequestProperty("connection", "Keep-Alive");
                conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
                conn.setDoOutput(true);
                conn.setDoInput(true);
                out = new PrintWriter(conn.getOutputStream());
                out.print(param);
                out.flush();
                in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                while (true) {
                    String line = in.readLine();
                    if (line == null) {
                        break;
                    }
                    result = result + line;
                }
                if (out != null) {
                    try {
                        out.close();
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
                if (in != null) {
                    in.close();
                }
            } catch (Exception e) {
                System.out.println("发送 POST 请求出现异常！" + e);
                e.printStackTrace();
                if (out != null) {
                    out.close();
                }
                if (in != null) {
                    in.close();
                }
            }
            return result;
        } catch (Throwable th) {
            if (out != null) {
                out.close();
            }
            if (in != null) {
                in.close();
            }
            throw th;
        }
    }
}
